<template>
	<view class="content">
		<image src="../../static/tinified/sm.png" mode="scaleToFill" @click="scanCode" />
		<image src="../../static/tinified/sd.png" mode="scaleToFill" @click="manual" />
		<!-- <image src="../../static/tinified/hy.png" mode="scaleToFill" /> -->

		<u-modal :show="showModal" title="核销码确认" showCancelButton @cancel="cancel" @confirm="confirm">
			<view class="slot-content">
				<view>姓名：{{ userList.username }}</view>
				<view>电话：{{ userList.tel }}</view>
				<view>身份：{{ userList.standing }}</view>
			</view>
		</u-modal>

		<!-- <u-modal :show="codeModal" title="验证码核验" showCancelButton @cancel="cancel" @confirm="confirm">
      <view class="slot-content">
        <u--input placeholder="请输入验证码" type="number" maxlength="6" prefixIconStyle="font-size: 22px;" placeholderStyle=" text-align: center;" border="bottom" v-model="value" shape="circle" @change="change"></u--input>
 

      </view>
    </u-modal> -->

		<u-keyboard mode="number" :dotDisabled="true" :show="codeModal" tips='验证码为6位数字' confirmText='完成'
			closeOnClickOverlay @change="changeFun" @close="closeFun" @cancel="closeFun" @confirm='confirmFun'
			@backspace="backspaceFun">
			<view class="flex_center u-bg-white u-p-t-40" style="text-align: center">
				<u-code-input v-model="value"></u-code-input>
			</view>
		</u-keyboard>
	</view>
</template>

<script>
	import {
		detail,
		verification
	} from '../../api/user'
	export default {
		data() {
			return {
				showModal: false,
				codeModal: false,
				show: false,
				userList: {},
				value: ''
			};
		},
		onShow() {},
		methods: {
			scanCode() {
				uni.navigateTo({
					url: "/pages/scancode/scancode",
				});
				var that = this;


				uni.scanCode({
					success: function(res) {
						console.log("条码类型：" + res.scanType);
						console.log("条码内容：" + res.result);
						if (!res.result) {
							that.$refs.uToast.show({
								icon: "error",
								message: "扫码失败",
								duration: 1500,
							});
						} else {


							that.content = "核销码:" + res.result;


							that.weight(res.result)
						}
					},
				});
			},
			manual() {
				// uni.showToast({
				//   icon: 'none',
				//   title: "正在开发中...",
				//   duration: 1500,
				// });
				this.codeModal = true
			},

			async weight(e) {
				await detail({
					order_id: e
				}).then(res => {
					console.log(res);

					if (res.status == 200) {
						this.conpon = res.data[0].order_id;
						this.userList = res.data[0]
						this.showModal = true;
					} else {
						uni.showToast({
							icon: "error",
							title: res.msg,
							duration: 1500,
						});
					}
				})
			},

			cancel() {
				this.showModal = false;
			},
			async confirm() {
				console.log(this.conpon, "1111111");
				await verification({
					order_id: this.conpon,
					admin_uid: uni.getStorageSync("uuid"),
					code: this.userList.code
				}).then((res) => {
					console.log(res, "核销成功");

					if (res.status == 200) {
						uni.showToast({
							icon: "default",
							title: res.msg,
							duration: 1500,
						})

					} else {
						uni.showToast({
							icon: "error",
							title: res.msg,
							duration: 1500,
						});
					}
					this.showModal = false;
				});
			},
			// 按键被点击(不包含退格键被点击)
			changeFun(e) {
				// 最多输入6为数字
				if (this.value.length >= 6) {
					return;
				}
				this.value += e;
			},
			// 键盘退格键被点击
			backspaceFun() {
				this.value = this.value.slice(0, -1);
			},
			// 确定 密码键盘
			confirmFun() {
				console.log('密码为：', this.value)
				this.weight(this.value)
				this.codeModal = false;
				this.value = '';
			},
			// 关闭 密码键盘
			closeFun() {
				this.codeModal = false;
				this.value = '';
			},

		},
	};
</script>
<style>
	page {
		background: #ffffff;
	}
</style>
<style lang="scss">
	.content {
		margin: 20rpx;
		padding-top: 30rpx;

		image {
			width: 100%;
			height: 180rpx;

			margin-bottom: 30rpx;
		}

		.flex_center {
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.u-bg-white {
			background-color: #fff;
		}

		.u-p-t-40 {
			padding-top: 40rpx;
		}
	}
</style>